import './utils'

export default function audioPlay (str) {
  let audioStatus = 'paused'
  const audio = document.createElement('audio')
  $.ajax({
    url: 'http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=' + encodeURI(str),
    type: 'get',
    dataType: 'blob' // 扩展出了blob类型
  }).done(function (data, status, jqXHR) {
    const reader = new window.FileReader()
    // console.log(reader)
    reader.readAsDataURL(data)
    reader.onloadend = function () {
      // console.log(reader.result)
      const base64 = reader.result.replace('x-bd-bv', 'wav')
      audio.src = base64
    }
  }).fail(function (jqXHR, textStatus) {
    console.warn(textStatus)
  })
  // 设置一个节流阀
  audio.play()
  audio.addEventListener('playing', function () {
    console.log(1)
    audioStatus = 'playing'
  })
  audio.addEventListener('pause', function () {
    audioStatus = 'paused'
  })
  // 怎么播放当前audio标签时,让其他标签暂停播放
}
